<template>
  <div class="app-container">
    <div class="all">
      <h2>今日，</h2>
      <div class="top">
        <div>
          2023年1月7日星期四，截至今日，经销商销售额为433.19元，其中累计佣金为325.96元
        </div>
        <div>
          <p>10</p>
          <p>新提现申请</p>
        </div>
      </div>
      <hr />
      <div class="content">
        <div class="content-1">
          <div>
            <div
              style="
                float: left;
                width: 5px;
                height: 25px;
                background: blue;
                margin: 0 20px 0 0;
              "
            ></div>
            <span>经销商佣金概括（元）</span>
          </div>
          <div class="content-1-2">
            <div style="width: 500px; height: 300px">
              <piechart :chartData="data_pie" />
            </div>
            <div class="pp">
              <p>经销商当前佣金：31900.73</p>
              <p>待结算：28000.20</p>
              <p>可提现：3900.53</p>
              <p>提现中：3900.53</p>
            </div>
          </div>
        </div>
        <div class="content-1">
          <div class="content-1-1">
            <div>
              <div
                style="
                  float: left;
                  width: 5px;
                  height: 25px;
                  background: blue;
                  margin: 0 20px 0 0;
                "
              ></div>
              <span>销售额/佣金曲线</span>
            </div>
            <div>
              <el-tabs v-model="activeName">
                <el-tab-pane name="1" label="近七天"></el-tab-pane>
                <el-tab-pane name="2" label="近6个月"></el-tab-pane>
              </el-tabs>
            </div>
          </div>
          <div class="content-1-2">
            <div style="width: 1000px; height: 300px">
              <lineEcharts :chartData="data" />
            </div>
          </div>
        </div>
      </div>
      <!-- <hr /> -->
      <div class="footer">
        <el-tabs v-model="activeKey">
          <el-tab-pane name="1" label="提现申请"></el-tab-pane>
          <el-tab-pane name="2" label="订单列表"></el-tab-pane>
        </el-tabs>
      </div>
    </div>

    <!-- 提现申请查询 -->
    <el-form
      v-if="activeKey == '1'"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="经销商名称" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入经销商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请时间" prop="orderNumber">
        <el-date-picker
          v-model="value1"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="提交状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 订单列表查询 -->
    <el-form
      v-if="activeKey == '2'"
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="70px"
    >
      <el-form-item label="订单号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经销商名称" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入经销商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="orderNumber">
        <el-date-picker
          v-model="value1"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间" prop="orderNumber">
        <el-date-picker
          v-model="value1"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <!-- 提现申请 -->
    <el-table
      v-if="activeKey == '1'"
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="经销商" align="center" prop="orderNumber" />
      <el-table-column label="申请人" align="center" prop="status" />
      <el-table-column label="提现金额" align="center" prop="iccid" />
      <el-table-column label="提现方式" align="center" prop="packageName" />
      <el-table-column label="提现状态" align="center" prop="transactionType" />
      <el-table-column
        label="审批凭证"
        align="center"
        prop="transactionAmount"
      />
      <el-table-column
        label="审批备注"
        align="center"
        prop="transactionAmount"
      />
      <el-table-column
        label="申请时间/审批时间"
        align="center"
        prop="transactionAmount"
      />

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:order:edit']"
            >提现审批</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!-- 订单列表 -->
    <el-table v-if="activeKey == '2'" v-loading="loading">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="订单号" align="center" prop="orderNumber" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="ICCID" align="center" prop="iccid" />
      <el-table-column label="套餐名称" align="center" prop="packageName" />
      <el-table-column label="交易金额" align="center" prop="transactionType" />
      <el-table-column label="佣金" align="center" prop="transactionAmount" />
      <el-table-column
        label="经销商名称"
        align="center"
        prop="transactionAmount"
      />
      <el-table-column label="负责人" align="center" prop="transactionAmount" />
      <el-table-column
        label="更新时间/创建时间"
        align="center"
        prop="updateTime"
      />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单管理对话框 -->
    <el-dialog
      title="提现审批"
      :visible.sync="open"
      width="500px"
      append-to-body
    >
      <div class="blockteacher">
        <span>提现方式：</span>
        <span>{{ record.assetExplain }}</span>
      </div>
      <div class="blockteacher">
        <span>姓名：</span>
        <span>{{ record.assetExplain }}</span>
      </div>
      <div class="blockteacher">
        <span>手机号：</span>
        <span>{{ record.assetExplain }}</span>
      </div>
      <div class="blockteacher">
        <span>微信账号：</span>
        <span>{{ record.assetExplain }}</span>
      </div>
      <div class="blockteacher">
        <span>提现金额：</span>
        <span>{{ record.assetExplain }}</span>
      </div>
      <div class="blockteacher">
        <span>审批凭证：</span>
        <span>{{ record.assetExplain }}</span>
      </div>
      <div class="blockteacher">
        <span>备注</span>
        <el-input
          type="textarea"
          placeholder="请输入内容"
          v-model="record.assetType"
          maxlength="30"
          show-word-limit
        >
        </el-input>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  addOrder,
  updateOrder,
} from "@/api/system/order";
import piechart from "@/views/dashboard/PieChart.vue";
import lineEcharts from "@/views/dashboard/LineChart.vue";
import { throws } from "assert";

export default {
  name: "Order",
  dicts: ["order_status", "trade_type"],
  components: {
    piechart,
    lineEcharts,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单管理表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        status: null,
        iccid: null,
        packageName: null,
        transactionType: null,
        transactionAmount: null,
        userId: null,
        cardId: null,
        packageId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      //饼图数据
      data_pie: {},
      //折线图数据
      data: {},
      //时间选择
      activeName: "1",
      //操作选择
      activeKey: "1",
      //时间选择器
      value1: "",
      //提现审批参数
      record: {
        assetExplain: "",
        assetType: "",
        chineseName: "",
        englishName: "",
      },
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    this.data_pie = {
      // days: ["11.21", "11.22", "11.23", "11.24", "11.25", "11.26", "11.27"],
      // data1: [100, 120, 161, 134, 105, 160, 165],
      // data2: [120, 82, 91, 154, 162, 140, 145],
      // a: [
      //   // 数据数组，name 为数据项名称，value 为数据项值
      //   { value: 40, name: "开卡数" },
      //   { value: 60, name: "库存数" },
      // ],
    };
    this.data = {
      expectedData: [4, 9, 12, 11, 5, 2, 9],
      actualData: [10, 4, 3, 11, 13, 10, 7],
    };
  },
  methods: {
    /** 查询订单管理列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNumber: null,
        status: null,
        iccid: null,
        packageName: null,
        transactionType: null,
        transactionAmount: null,
        userId: null,
        cardId: null,
        packageId: null,
        createTime: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /* 提现审批 */ /* 后面接口联调再写 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.record.assetExplain = row.iccid;
    },

    // /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加订单管理";
    // },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   console.log(row);
    //   const id = row.id || this.ids;
    //   getOrder(id).then((response) => {
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改订单管理";
    //   });
    // },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除订单管理编号为"' + ids + '"的数据项？')
        .then(function () {
          return delOrder(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/order/export",
        {
          ...this.queryParams,
        },
        `order_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped lang="scss">
.all::-webkit-scrollbar {
  display: none;
}
.all {
  overflow: hidden; // 隐藏超出部分
  overflow-y: scroll;
  width: 100%;
  // height: 100vh;
  max-height: 100%; // 你可以设置固定或者最大最小高度
  background-color: white;
  padding: 5px;
  * {
    margin: 0;
    padding: 0;
  }
  .top {
    width: 100%;
    height: 3%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;

    p:first-child {
      font-size: 30px;
    }
  }

  .content {
    width: 100%;
    height: 50%;
    display: flex;
    margin: 0 0 20px 0;

    .content-1 {
      display: flex;
      width: 50%;
      flex-direction: column;
      margin: 10px 20px 0 0;

      .content-1-1 {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: -15px 0 0 0;
      }
      .content-1-2 {
        width: 500px;
        height: 300px;
        display: flex;
        align-items: center;

        .pp {
          text-align: center;
        }
      }
    }
  }

  .blockteacher {
    width: 80%;
    span {
      width: 80px;
      display: inline-block;
      margin: 30px 30px 0 30px;
    }
    span:nth-child(2) {
      width: 250px;
    }
  }
}
</style>
